﻿<!--
// SIMPLE INHERITANCE JOOPL SAMPLE

// (c) joopl
// By Matías Fidemraizer (http://www.matiasfidemraizer.com) (http://www.linkedin.com/in/mfidemraizer/en)
// -------------------------------------------------
// http://joopl.codeplex.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jOOPL · Simple inheritance sample</title>

    <script type="text/javascript" src="joopl.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        (function () {
            "use strict";

            // #1 Declare a namespace
            $namespace.register("Joopl.Samples", function () {

                // #2 Declare a class "ClassA" inside the registered namespace.
                // The ClassA has a method "someMethod()" which adds a text to the document.
                this.ClassA = $def({
                    $members: {
                        // Adds the whole text to the document
                        someMethod: function () {
                            document.body.appendChild(document.createTextNode("Hello world from base class!"));
                        }
                    }
                });

                // #3 ClassB inherits ClassA and it does not add any member but
                // as it derives from ClassA, it will have access to "someMethod()" of
                // ClassA.
                this.ClassB = $def({
                    $constructor: function () {
                        this.$base.$ctor();
                    },
                    $members: {
                    },
                    $extends: this.ClassA
                });
            });

            // #4 Create a namespace scope in order to have access to both declared classes in the registered
            // namespace.
            $namespace.using(["Joopl.Samples"], function () {
                var b = new this.ClassB();
                // As expected, ClassB instance has "someMethod()" and this will print the expected text
                // to the document.
                 b.someMethod();
            });
        })();
    </script>
</body>
</html>
